home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun3.md / mach.h < prev    next >
C/C++ Source or Header  |  1991-07-26  |  8KB  |  263 lines

  1. /*
  2.  * mach.h --
  3.  *
  4.  *     Exported structures for the mach module.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/kernel/mach/sun3.md/RCS/mach.h,v 9.10 91/07/26 17:03:15 shirriff Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _MACH
  19. #define _MACH
  20.  
  21. #ifdef KERNEL
  22. #include <devAddrs.h>
  23. #include <machTypes.h>
  24. #include <procMigrate.h>
  25. #include <user/fmt.h>
  26. #else
  27. #include <kernel/devAddrs.h>
  28. #include <kernel/machTypes.h>
  29. #include <kernel/procMigrate.h>
  30. #include <fmt.h>
  31. #endif
  32.  
  33.  
  34. /*
  35.  * Macros to disable and enable interrupts.
  36.  */
  37. #define    Mach_DisableIntr()    asm("movw #0x2700,sr")
  38. #define    Mach_EnableIntr()    asm("movw #0x2000,sr")
  39. #define DISABLE_INTR() \
  40.     if (!Mach_AtInterruptLevel()) { \
  41.     Mach_DisableIntr(); \
  42.     if (mach_NumDisableIntrsPtr[0] < 0) { \
  43.         panic("Negative interrupt count.\n"); \
  44.     } \
  45.     mach_NumDisableIntrsPtr[0]++; \
  46.     }
  47. #define ENABLE_INTR() \
  48.     if (!Mach_AtInterruptLevel()) { \
  49.     mach_NumDisableIntrsPtr[0]--; \
  50.     if (mach_NumDisableIntrsPtr[0] < 0) { \
  51.         panic("Negative interrupt count.\n"); \
  52.     } \
  53.     if (mach_NumDisableIntrsPtr[0] == 0) { \
  54.         Mach_EnableIntr(); \
  55.     } \
  56.     }
  57.  
  58. /*
  59.  * Macro to get level of nesting of disabled interrupts.
  60.  */
  61. #define Mach_IntrNesting(cpu) (mach_NumDisableIntrsPtr[(cpu)])
  62.  
  63. /*
  64.  * A macro to test if the current processor is at interrupt level.
  65.  */
  66.  
  67. #define    Mach_AtInterruptLevel()    (mach_AtInterruptLevel)
  68.  
  69. /*
  70.  * A macro to test if the current processor is in kernel mode.
  71.  */
  72.  
  73. #define    Mach_KernelMode() (mach_KernelMode)
  74.  
  75. /*
  76.  * Delay for N microseconds.
  77.  */
  78. #ifdef sun3
  79. #define    MACH_DELAY(n)    { register int N = (n)<<1; N--; while (N > 0) {N--;} }
  80. #else
  81. #define    MACH_DELAY(n)    { register int N = (n)>>1; N--; while (N > 0) {N--;} }
  82. #endif
  83.  
  84. /*
  85.  * The interrupt register on a sun3.
  86.  */
  87. #define    Mach_InterruptReg  ((volatile unsigned char *) DEV_INTERRUPT_REG_ADDR)
  88.  
  89. /*
  90.  * Dispatch tables for kernel calls.
  91.  */
  92. extern ReturnStatus (*(mach_NormalHandlers[]))();
  93. extern ReturnStatus (*(mach_MigratedHandlers[]))();
  94.  
  95. /*
  96.  * Macro to get processor number
  97.  */
  98. #define    Mach_GetProcessorNumber()     0
  99.  
  100. /*
  101.  * Macro to get the user's stack pointer.
  102.  */
  103. #define Mach_UserStack() (machCurStatePtr->userState.userStackPtr)
  104.  
  105.  
  106. /*
  107.  *----------------------------------------------------------------------
  108.  *
  109.  * Mach_GetPC --
  110.  *
  111.  *    Returns the PC of the current instruction.
  112.  *
  113.  * Results:
  114.  *    Current PC
  115.  *
  116.  * Side effects:
  117.  *    None.
  118.  *
  119.  *----------------------------------------------------------------------
  120.  */
  121.  
  122. #ifdef lint
  123. #define Mach_GetPC()     0
  124. #else
  125. #define Mach_GetPC() \
  126.     ({\
  127.     register Address __pc; \
  128.     asm volatile ("1:\n\tlea\t1b,%0\n":"=a" (__pc));\
  129.     (__pc);\
  130.     })
  131. #endif
  132.  
  133.  
  134. /*
  135.  *----------------------------------------------------------------------
  136.  *
  137.  * Mach_GetCallerPC --
  138.  *
  139.  *    Returns the PC of the caller of the current routine.
  140.  *
  141.  * Results:
  142.  *    Our caller's PC.
  143.  *
  144.  * Side effects:
  145.  *    None.
  146.  *
  147.  *----------------------------------------------------------------------
  148.  */
  149.  
  150. #ifdef lint
  151. #define Mach_GetCallerPC()     0
  152. #else
  153. #define Mach_GetCallerPC() \
  154.     ({\
  155.     register Address __pc; \
  156.     asm volatile ("\tmovl a6@(4),%0\n":"=a" (__pc));\
  157.     __pc;\
  158.     })
  159. #endif
  160.  
  161. /*
  162.  * Suns don't have a write buffer, but this macro makes it easier to
  163.  * write machine-independent device drivers for both the Decstations and Suns.
  164.  */
  165. #define Mach_EmptyWriteBuffer()
  166.  
  167. #define Mach_SetErrno(err) Proc_GetActualProc()->unixErrno = (err)
  168.  
  169. extern    Boolean    mach_KernelMode;
  170. extern    int    mach_NumProcessors;
  171. extern    Boolean    mach_AtInterruptLevel;
  172. extern    int    *mach_NumDisableIntrsPtr;
  173. /*
  174.  * mach_MachineType is a string used to expand $MACHINE in pathnames.
  175.  */
  176. extern    char    *mach_MachineType;
  177. /*
  178.  * mach_Format defines a byte ordering/structure alignment type
  179.  * used when servicing IOControls.  The input and output buffers for
  180.  * IOControls have to be made right by the server.
  181.  */
  182. extern    Fmt_Format    mach_Format;
  183.  
  184. /*
  185.  * Routine to initialize mach module.  Must be called first as part of boot 
  186.  * sequence.
  187.  */
  188. extern void Mach_Init _ARGS_((void));
  189.  
  190.  
  191.  
  192. /*
  193.  * Routines to munge machine state struct.
  194.  */
  195. extern void Mach_InitFirstProc _ARGS_((Proc_ControlBlock *procPtr));
  196. extern ReturnStatus Mach_SetupNewState _ARGS_((Proc_ControlBlock *procPtr, Mach_State *fromStatePtr, void (*startFunc)(), Address startPC, Boolean user));
  197. extern void Mach_SetReturnVal _ARGS_((Proc_ControlBlock *procPtr, int retVal,
  198.     int retVal2));
  199. extern void Mach_StartUserProc _ARGS_((Proc_ControlBlock *procPtr, Address entryPoint));
  200. extern void Mach_ExecUserProc _ARGS_((Proc_ControlBlock *procPtr, Address userStackPtr, Address entryPoint));
  201. extern void Mach_FreeState _ARGS_((Proc_ControlBlock *procPtr));
  202. extern void Mach_CopyState _ARGS_((Mach_State *statePtr, Proc_ControlBlock *destProcPtr));
  203. extern void Mach_GetDebugState _ARGS_((Proc_ControlBlock *procPtr, Proc_DebugState *debugStatePtr));
  204. extern void Mach_SetDebugState _ARGS_((Proc_ControlBlock *procPtr, Proc_DebugState *debugStatePtr));
  205. extern Address Mach_GetUserStackPtr _ARGS_((Proc_ControlBlock *procPtr));
  206.  
  207. /*
  208.  * Migration routines.
  209.  */
  210. extern ReturnStatus Mach_EncapState _ARGS_((register Proc_ControlBlock *procPtr, int hostID, Proc_EncapInfo *infoPtr, Address buffer));
  211. extern ReturnStatus Mach_DeencapState _ARGS_((register Proc_ControlBlock *procPtr, Proc_EncapInfo *infoPtr, Address buffer));
  212. extern ReturnStatus Mach_GetEncapSize _ARGS_((Proc_ControlBlock *procPtr, int hostID, Proc_EncapInfo *infoPtr));
  213. extern Boolean Mach_CanMigrate _ARGS_((Proc_ControlBlock *procPtr));
  214. extern int Mach_GetLastSyscall _ARGS_((void));
  215.  
  216. /*
  217.  * Other routines.
  218.  */
  219. extern void Mach_InitSyscall _ARGS_((int callNum, int numArgs, ReturnStatus (*normalHandler)(), ReturnStatus (*migratedHandler)()));
  220. extern void Mach_SetHandler _ARGS_((int vectorNumber, int (*handler)(), ClientData clientData));
  221. extern int Mach_GetExcStackSize _ARGS_((Mach_ExcStack *excStackPtr));
  222. extern Mach_ProcessorStates Mach_ProcessorState _ARGS_((int processor));
  223. extern int Mach_GetNumProcessors _ARGS_((void));
  224.  
  225. extern ReturnStatus    Mach_Probe _ARGS_((int byteCount, Address readAddress, Address writeAddress));
  226.  
  227. /*
  228.  * Machine dependent routines.
  229.  */
  230. extern  Net_EtherAddress        *Mach_GetEtherAddress _ARGS_((Net_EtherAddress *etherAddress));
  231. extern  void    Mach_ContextSwitch _ARGS_((Proc_ControlBlock *fromProcPtr, Proc_ControlBlock *toProcPtr));
  232. extern  int     Mach_TestAndSet _ARGS_((int *intPtr));
  233. extern  int     Mach_GetMachineType _ARGS_((void));
  234. extern int Mach_GetMachineArch _ARGS_((void));
  235. extern void Mach_CheckSpecialHandling _ARGS_((int pnum));
  236. extern int Mach_GetBootArgs _ARGS_((int argc, int bufferSize, char **argv, char *buffer));
  237. extern    Address    Mach_GetStackPointer _ARGS_((void));
  238. extern void Mach_Return2 _ARGS_((int val));
  239. extern int Mach_SigreturnStub _ARGS_((void));
  240.  
  241. /*
  242.  * spriteStart is defined in bootSys.s with an underscore.
  243.  */
  244. extern    int        spriteStart;
  245. extern    int        endBss;
  246. extern    int        endText;
  247.  
  248. /*
  249.  * Machine dependent variables.
  250.  */
  251. extern    Address    mach_KernStart;
  252. extern    Address    mach_CodeStart;
  253. extern    Address    mach_StackBottom;
  254. extern    int    mach_KernStackSize;
  255. extern    Address    mach_KernEnd;
  256. extern    Address    mach_FirstUserAddr;
  257. extern    Address    mach_LastUserAddr;
  258. extern    Address    mach_MaxUserStackAddr;
  259. extern    int    mach_LastUserStackPage;
  260. extern    Mach_State    *machCurStatePtr;
  261.  
  262. #endif /* _MACH */
  263.